package engine;

import java.util.ArrayList;

/**
 *
 * @author Johnny
 */
public class Instance {

    private int id;
    private ArrayList<Time> schedules;

    public Instance(int id, ArrayList<Time> schedules) {
        this.id = id;
        this.schedules = schedules;
    }

    public Instance(int id) {
        this(id,new ArrayList<Time>());
    }

    public int getId() {
        return id;
    }

    public ArrayList<Time> getSchedules() {
        return schedules;
    }

    /**
     * Returns the number of schedules.
     * @return the number of schedules.
     */
    public int getScheduleNr() {
        return schedules.size();
    }

    void setSchedules(ArrayList<Time> schedules) {
        this.schedules = schedules;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Instance other = (Instance) obj;
        if (this.id != other.id) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 29 * hash + this.id;
        return hash;
    }

    

    @Override
    public String toString() {
//        StringBuffer sb = new StringBuffer();
//        sb.append(id);
//        sb.append("( ");
//        for (Time time: schedules) {
//            sb.append(time);
//            sb.append(' ');
//        }
//        sb.append(')');
//        return sb.toString();
        String text;
        switch (schedules.size()) {
            case 0:
                text = "[" + id + "]";
                break;
            case 1:
                text = schedules.get(0).toString();
                break;
            default:
                text = schedules.get(0).toString() + "-" +
                        schedules.get(schedules.size()-1).toString();
                break;
        }
        return text;
    }
}
